package com.zerowidth.db.op;

import com.zerowidth.db.DBHelper;
import com.zerowidth.db.base.SqlResult;
import com.zerowidth.db.bean.ExchangeCodeBean;
import com.zerowidth.db.utils.IOUtils;

import java.util.Locale;

public class ExchangeCodeDB {

    public static ExchangeCodeBean findBean(String code) {
        String sql = String.format(Locale.getDefault(), "SELECT * FROM exchange_code WHERE code = '%s'", code);

        SqlResult sr = DBHelper.executeQueryEx(sql);

        try {
            if (sr != null && sr.rs != null && sr.rs.next()) {

                ExchangeCodeBean bean = new ExchangeCodeBean();

                bean.id = sr.rs.getInt("id");
                bean.code = sr.rs.getString("code");
                bean.type = sr.rs.getInt("type");
                bean.state = sr.rs.getInt("state");
                bean.user_id = sr.rs.getString("user_id");
                bean.create_time = sr.rs.getString("create_time");
                bean.active_time = sr.rs.getString("active_time");

                return bean;
            }

        } catch (Exception e) {

        } finally {
            IOUtils.close(sr);
        }


        return null;
    }

}
